<?php
/**
 * Created by .
 * User: luogan
 * Date: 2022/1/17
 */

namespace app\admin\controller\v1;


use app\admin\service\MenuService;
use app\admin\validate\MenuValidate;
use app\interfaces\AdminInterface;
use hg\apidoc\annotation as Apidoc;
/**
 * @Apidoc\Title("菜单管理")
 * @Apidoc\Group("system")
 * @Apidoc\Sort(2)
 */
class Menu extends Base implements AdminInterface
{
    protected $service;

    protected $validate;

    public function __construct()
    {
        $this->service = new MenuService();
        $this->validate = new MenuValidate();
    }

    /**
     * @Apidoc\Title("菜单列表")
     * @Apidoc\Desc("菜单列表")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/menu/list")
     * @Apidoc\Tag("菜单")
     * @Apidoc\Returned(type="array",ref="app\model\menuModel\getMenuTreeList",default="菜单列表")
     */
    public function list()
    {

        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->getList($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("菜单详情")
     * @Apidoc\Desc("菜单详情")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/menu/info")
     * @Apidoc\Tag("菜单")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="菜单id")
     * @Apidoc\Returned(ref="app\model\menuModel\getMenu")
     */
    public function info()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->getInfo($data['id']);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("菜单新增")
     * @Apidoc\Desc("菜单新增")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/menu/add")
     * @Apidoc\Tag("菜单")
     * @Apidoc\Param("title",type="int",require=true,default="1",desc="标题")
     * @Apidoc\Param("icon",type="string",require=true,default="1",desc="图标")
     * @Apidoc\Param("type",type="int",require=true,default="1",desc="菜单类型：0：目录；1：菜单；2: 按钮")
     * @Apidoc\Param("parent_id",type="int",require=true,default="1",desc="上级分类ID")
     * @Apidoc\Param("component",type="string",require=true,default="1",desc="前端组件名")
     * @Apidoc\Param("path",type="string",require=true,default="1",desc="前端路由")
     * @Apidoc\Param("action",type="string",require=true,default="1",desc="权限标识")
     * @Apidoc\Param("module",type="string",require=true,default="1",desc="模块")
     * @Apidoc\Param("controller",type="string",require=true,default="1",desc="控制器")
     * @Apidoc\Param("method",type="string",require=true,default="1",desc="方法")
     * @Apidoc\Param("sort",type="int",require=true,default="1",desc="排序")
     * @Apidoc\Param("target",type="string",require=true,default="1",desc="链接跳转方式")
     * @Apidoc\Param("status",type="int",require=true,default="1",desc="状态：0：正常 1：禁用")
     * @Apidoc\Returned(ref="app\model\menuModel\getMenu")
     */
    public function add()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->create($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("菜单更新")
     * @Apidoc\Desc("菜单更新")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/menu/edit")
     * @Apidoc\Tag("菜单")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="菜单id")
     * @Apidoc\Param("title",type="int",require=true,default="1",desc="标题")
     * @Apidoc\Param("icon",type="string",require=true,default="1",desc="图标")
     * @Apidoc\Param("type",type="int",require=true,default="1",desc="菜单类型：0：目录；1：菜单；2: 按钮")
     * @Apidoc\Param("parent_id",type="int",require=true,default="1",desc="上级分类ID")
     * @Apidoc\Param("component",type="string",require=true,default="1",desc="前端组件名")
     * @Apidoc\Param("path",type="string",require=true,default="1",desc="前端路由")
     * @Apidoc\Param("action",type="string",require=true,default="1",desc="权限标识")
     * @Apidoc\Param("module",type="string",require=true,default="1",desc="模块")
     * @Apidoc\Param("controller",type="string",require=true,default="1",desc="控制器")
     * @Apidoc\Param("method",type="string",require=true,default="1",desc="方法")
     * @Apidoc\Param("sort",type="int",require=true,default="1",desc="排序")
     * @Apidoc\Param("target",type="string",require=true,default="1",desc="链接跳转方式")
     * @Apidoc\Param("status",type="int",require=true,default="1",desc="状态：0：正常 1：禁用")
     */
    public function edit()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->update($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("菜单删除")
     * @Apidoc\Desc("菜单删除")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/menu/del")
     * @Apidoc\Tag("菜单")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="菜单id")
     */
    public function del()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->delete($data['id']);
        return success('操作成功',$result);
    }
}
